<ui:composition xmlns="http://www.w3.org/1999/xhtml"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:c="http://java.sun.com/jsp/jstl/core"
     xmlns:p="http://primefaces.org/ui"
     xmlns:o="http://omnifaces.org/ui"
     xmlns:of="http://omnifaces.org/functions"
     xmlns:jsf="http://xmlns.jcp.org/jsf">

    <c:set var="page" value="/dataverse/#{DataversePage.dataverse.alias}"/>
    <c:set var="cvocConf" value="#{settingsWrapper.getCVocConf(true)}"/>
    <p:fragment>
        <p:autoUpdate/>
        <ui:repeat value="#{DatasetPage.vocabScripts}" var="vocabScriptUrl">
            <script defer="defer" src="#{vocabScriptUrl}?version=#{settingsWrapper.appVersion}"/>
        </ui:repeat>
    </p:fragment>
    <!-- Search Form + Add Data Button -->
    <div class="row panelSearchForm" jsf:rendered="#{!SearchIncludeFragment.solrIsDown}">
        <div class="#{widgetWrapper.widgetView ? 'col-xs-12' : 'col-sm-9'}">
            <h:form styleClass="form-inline">
                <div class="form-group">
                    <div class="input-group">
                        <p:inputText id="searchBasic" title="#{bundle.search}" styleClass="form-control search-input" size="35" value="#{SearchIncludeFragment.query}" onkeypress="if (event.keyCode == 13) { submitsearch(); return false; }">
                            <f:passThroughAttribute name="aria-label" value="#{bundle.search}"/>
                        </p:inputText>
                        <p:watermark for="searchBasic" value="#{dataverseRedirectPage == 'dataverseuser.xhtml' ? bundle['account.search.input.watermark'] : bundle['dataverse.search.input.watermark']}"/>

                        <span class="input-group-btn">
                            <p:commandLink id="searchbutton" title="#{bundle['dataverse.search.btn.find']}" ariaLabel="#{bundle['dataverse.search.btn.find']}" styleClass="btn btn-default bootstrap-button-tooltip" 
                                           action="#{SearchIncludeFragment.searchRedirect(dataverseRedirectPage, DataversePage.dataverse)}">
                                <span class="glyphicon glyphicon-search no-text"/>
                            </p:commandLink>
                        </span>

                        <p:remoteCommand name="submitsearch" action="#{SearchIncludeFragment.searchRedirect(dataverseRedirectPage, DataversePage.dataverse)}"/>
                    </div>
                    <h:outputLink rel="nofollow" id="advsearchlink" value="#{widgetWrapper.wrapURL('/search/advanced.xhtml')}">
                        <f:param name="dataverseIdentifier" value="#{SearchIncludeFragment.dataverse.alias}"/>
                        <h:outputText value="#{bundle['dataverse.search.advancedSearch']}"/>
                        <!--<f:param name="q" value="#{SearchIncludeFragment.query}" disable="#{empty SearchIncludeFragment.query}"/>-->
                    </h:outputLink>
                </div>
            </h:form>
        </div>
        <div class="col-sm-3 text-right col-manage-action" jsf:rendered="#{!widgetWrapper.widgetView}">
            <div class="button-block">
                <!-- ADD DATA -->
                <o:importFunctions type="edu.harvard.iq.dataverse.authorization.groups.impl.builtin.AuthenticatedUsers" />
                <ui:fragment rendered="#{!dataverseSession.user.authenticated and (permissionsWrapper.authUsersCanCreateDataversesInDataverse(SearchIncludeFragment.dataverse)
                                         or permissionsWrapper.authUsersCanCreateDatasetsInDataverse(SearchIncludeFragment.dataverse))}">
                    <button type="button" class="btn btn-default btn-access" onclick="PF('addData_popup').show()">
                        <span class="glyphicon glyphicon-plus"/> #{bundle['dataverse.results.btn.addData']}
                    </button>
                </ui:fragment>
                <h:form id="addDataForm" class="btn-form"
                        rendered="#{dataverseSession.user.authenticated and (permissionsWrapper.canIssueCreateDataverseCommand(SearchIncludeFragment.dataverse)
                                     or permissionsWrapper.canIssueCreateDatasetCommand(SearchIncludeFragment.dataverse))}">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default btn-access dropdown-toggle" data-toggle="dropdown">
                            <span class="glyphicon glyphicon-plus"/> #{bundle['dataverse.results.btn.addData']} <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu pull-right text-left">
                            <ui:fragment rendered="#{permissionsWrapper.canIssueCreateDataverseCommand(SearchIncludeFragment.dataverse) }">
                                <li><a href="/dataverse.xhtml?ownerId=#{SearchIncludeFragment.dataverse.id}">#{bundle['dataverse.results.btn.addData.newDataverse']}</a></li>
                            </ui:fragment>
                            <ui:fragment rendered="#{permissionsWrapper.canIssueCreateDatasetCommand(SearchIncludeFragment.dataverse) }">
                                <li><a href="/dataset.xhtml?ownerId=#{SearchIncludeFragment.dataverse.id}">#{bundle['dataverse.results.btn.addData.newDataset']}</a></li>
                            </ui:fragment>
                        </ul>
                    </div>
                </h:form>
            </div>
        </div>
    </div>

    <!-- Message Block / SOLR IS DOWN -->
    <div class="row" jsf:rendered="#{SearchIncludeFragment.solrIsDown}">
        <div class="col-sm-12">
            <div class="bg-danger padding-12 margin-bottom">
                <span class="glyphicon glyphicon-warning-sign text-danger"/>&#160;

                <h:outputText value="#{SearchIncludeFragment.searchException.message}" styleClass="text-danger highlightBold"/>

                <h:outputText value=" - #{bundle['dataverse.results.solrIsDown']}" styleClass="text-danger"/>
            </div>
            <pre><h:outputText value="#{SearchIncludeFragment.searchException.cause.message}"/></pre>
        </div>
    </div>
    
    
    <!-- ... And the message block for when SOLR IS DOWN *TEMPORARILY* -->
    <div class="row" jsf:rendered="#{SearchIncludeFragment.solrTemporarilyUnavailable}">
        <div class="col-sm-12">
            <div class="bg-danger padding-12 margin-bottom">
                <h:outputText value="#{bundle['dataverse.results.solrIsTemporarilyUnavailable']}" styleClass="highlightBold"/>
            </div>
            <pre><h:outputText value="#{bundle['dataverse.results.solrIsTemporarilyUnavailable.extraText']}"/></pre>
        </div>
    </div>

    <!-- Search Results / SOLR IS UP -->
    <div id="search-row-panel" class="row row-offcanvas row-offcanvas-left" jsf:rendered="#{!(SearchIncludeFragment.solrIsDown or SearchIncludeFragment.solrTemporarilyUnavailable)}">
        <div id="dv-sidebar" class="col-sm-4 col-md-3 sidebar-offcanvas">
            <!--TYPE FACET (DATAVERSES, DATASETS, FILES)-->
            <h:form id="facetType" rendered="#{!SearchIncludeFragment.facetsDisabled}">
                <!--DATAVERSE TOGGLE-->
                <div class="clearfix">
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" styleClass="facetTypeChBox facetLink #{SearchIncludeFragment.selectedTypesList.contains('dataverses') ? 'facetSelected': ''}" disabled="#{SearchIncludeFragment.getNewSelectedTypes('dataverses') == null}">
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <f:param name="types" value="#{SearchIncludeFragment.getNewSelectedTypes('dataverses')}"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                        </c:forEach>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                        <f:param name="page" value="1"/>
                        <f:passThroughAttribute name="aria-label" value="#{bundle['facet.collection.label']}"/>
                        <p:selectBooleanCheckbox value="#{SearchIncludeFragment.selectedTypesList.contains('dataverses') ? true : false}" disabled="#{SearchIncludeFragment.getNewSelectedTypes('dataverses') == null ? true : false}" ariaLabel="#{bundle['facet.collection.label']}"/>
                    </h:outputLink>
                    <!--DATAVERSES ONLY-->
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" disabled="#{false}" styleClass="facetTypeLink chkbox-label-margin #{SearchIncludeFragment.selectedTypesList.contains('dataverses') ? 'facetSelected': ''}">
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <f:param name="types" value="dataverses"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                        </c:forEach>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                        <f:param name="page" value="1"/>

                        <span class="icon-dataverse text-icon-inline"></span>

                        <h:outputFormat rendered="#{!SearchIncludeFragment.uncheckedTypesFacetDisabled or SearchIncludeFragment.selectedTypesList.contains('dataverses')}" styleClass="facetTypeDataverse" value="#{bundle['dataverse.results.types.dataverses']} &#40;{0}&#41;">
                            <f:param value="#{SearchIncludeFragment.facetCountDataverses}"/>
                        </h:outputFormat>
                        <h:outputText rendered="#{SearchIncludeFragment.uncheckedTypesFacetDisabled and !SearchIncludeFragment.selectedTypesList.contains('dataverses')}" value="#{bundle['dataverse.results.types.dataverses']}" styleClass="facetTypeDataverse"/>
                    </h:outputLink>
                </div>
                <!--DATASETS TOGGLE-->
                <div class="clearfix">
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" styleClass="facetTypeChBox facetLink #{SearchIncludeFragment.selectedTypesList.contains('datasets') ? 'facetSelected': ''}" disabled="#{SearchIncludeFragment.getNewSelectedTypes('datasets') == null}">
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <f:param name="types" value="#{SearchIncludeFragment.getNewSelectedTypes('datasets')}"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                        </c:forEach>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                        <f:param name="page" value="1"/>
                        <f:passThroughAttribute name="aria-label" value="#{bundle['facet.dataset.label']}"/>
                        <p:selectBooleanCheckbox value="#{SearchIncludeFragment.selectedTypesList.contains('datasets') ? true : false}" disabled="#{SearchIncludeFragment.getNewSelectedTypes('datasets') == null ? true : false}" ariaLabel="#{bundle['facet.dataset.label']}"/>
                    </h:outputLink>
                    <!--DATASETS ONLY-->
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" disabled="#{false}" styleClass="facetTypeLink chkbox-label-margin #{SearchIncludeFragment.selectedTypesList.contains('datasets') ? 'facetSelected': ''}">
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <f:param name="types" value="datasets"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                        </c:forEach>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                        <f:param name="page" value="1"/>

                        <span class="icon-dataset text-icon-inline"></span>

                        <h:outputFormat rendered="#{!SearchIncludeFragment.uncheckedTypesFacetDisabled or SearchIncludeFragment.selectedTypesList.contains('datasets')}" styleClass="facetTypeDataset" value="#{bundle['dataverse.results.types.datasets']} &#40;{0}&#41;">
                            <f:param value="#{SearchIncludeFragment.facetCountDatasets}"/>
                        </h:outputFormat>
                        <h:outputText rendered="#{SearchIncludeFragment.uncheckedTypesFacetDisabled and !SearchIncludeFragment.selectedTypesList.contains('datasets')}" value="#{bundle['dataverse.results.types.datasets']}" styleClass="facetTypeDataset"/>
                    </h:outputLink>
                </div>
                <!--FILES TOGGLE-->
                <div class="clearfix">
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" styleClass="facetTypeChBox facetLink #{SearchIncludeFragment.selectedTypesList.contains('files') ? 'facetSelected': ''}" disabled="#{SearchIncludeFragment.getNewSelectedTypes('files') == null}">
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <f:param name="types" value="#{SearchIncludeFragment.getNewSelectedTypes('files')}"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                        </c:forEach>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                        <f:param name="page" value="1"/>
                        <f:passThroughAttribute name="aria-label" value="#{bundle['facet.datafile.label']}"/>
                        <p:selectBooleanCheckbox value="#{SearchIncludeFragment.selectedTypesList.contains('files') ? true : false}" disabled="#{SearchIncludeFragment.getNewSelectedTypes('files') == null ? true : false}" ariaLabel="#{bundle['facet.datafile.label']}"/>
                    </h:outputLink>
                    <!--FILES ONLY-->
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" disabled="#{false}" styleClass="facetTypeLink chkbox-label-margin #{SearchIncludeFragment.selectedTypesList.contains('files') ? 'facetSelected': ''}">
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <f:param name="types" value="files"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                        </c:forEach>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                        <f:param name="page" value="1"/>

                        <span class="icon-file text-icon-inline"></span>

                        <h:outputFormat rendered="#{!SearchIncludeFragment.uncheckedTypesFacetDisabled or SearchIncludeFragment.selectedTypesList.contains('files')}" styleClass="facetTypeFile" value="#{bundle['dataverse.results.types.files']} &#40;{0}&#41;">
                            <f:param value="#{SearchIncludeFragment.facetCountFiles}"/>
                        </h:outputFormat>
                        <h:outputText rendered="#{SearchIncludeFragment.uncheckedTypesFacetDisabled and !SearchIncludeFragment.selectedTypesList.contains('files')}" value="#{bundle['dataverse.results.types.files']}" styleClass="facetTypeFile"/>
                    </h:outputLink>
                </div>
            </h:form>

            <!--NON-TYPE FACETS-->
            <h:form id="facetCategoryForm" rendered="#{(DataversePage.searchResultsCount > 0) and !SearchIncludeFragment.facetsDisabled}">
                <p:dataList id="facetCategoryList" value="#{DataversePage.facetCategoryList}" var="facetCategory">
                    <h:outputText value="#{facetCategory.friendlyName}" styleClass="facetCategoryName"/>
                    <p:dataList value="#{facetCategory.facetLabel}" var="facetLabel" rows="#{DataversePage.getNumberOfFacets(facetCategory.name,5)}">
                        <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" rendered="#{!DataversePage.filterQueries.contains(facetLabel.filterQuery)}" styleClass="facetLink">
                            <h:outputText value="#{facetLabel.name}">
                                <c:if test="#{!cvocConf.isEmpty()}">
                                    <f:passThroughAttribute name="lang" value="#{DatasetPage.getFieldLanguage(cvocConf.get(facetCategory.datasetFieldTypeId).getString('languages'))}" />
                                    <f:passThroughAttribute name="data-cvoc-service-url" value="#{cvocConf.get(facetCategory.datasetFieldTypeId).getString('cvoc-url','')}" />
                                    <f:passThroughAttribute name="data-cvoc-headers" value="#{cvocConf.get(facetCategory.datasetFieldTypeId).containsKey('headers') ? cvocConf.get(facetCategory.datasetFieldTypeId).get('headers').toString() : '{}'}"/>
                                    <f:passThroughAttribute name="data-cvoc-protocol" value="#{cvocConf.get(facetCategory.datasetFieldTypeId).getString('protocol','')}" />
                                </c:if>
                            </h:outputText>
                            <h:outputFormat value=" &#40;{0}&#41;">
                                <f:param value="#{facetLabel.count}"/>
                            </h:outputFormat>
                            <f:param name="q" value="#{DataversePage.query}"/>
                            <f:param name="fq#{DataversePage.filterQueries.size()}" value="#{facetLabel.filterQuery}"/>
                            <c:forEach items="#{DataversePage.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                            </c:forEach>
                            <f:param name="types" value="#{DataversePage.selectedTypesString}"/>
                            <f:param name="sort" value="#{DataversePage.sortField}"/>
                            <f:param name="order" value="#{DataversePage.sortOrder}"/>
                        </h:outputLink>

                        <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" rendered="#{DataversePage.filterQueries.contains(facetLabel.filterQuery)}" styleClass="facetLink facetSelected">
                            <h:outputText value="#{facetLabel.name}">
                                <c:if test="#{!cvocConf.isEmpty()}">
                                    <f:passThroughAttribute name="lang" value="#{DatasetPage.getFieldLanguage(cvocConf.get(facetCategory.datasetFieldTypeId).getString('languages'))}" />
                                    <f:passThroughAttribute name="data-cvoc-service-url" value="#{cvocConf.get(facetCategory.datasetFieldTypeId).getString('cvoc-url','')}" />
                                    <f:passThroughAttribute name="data-cvoc-headers" value="#{cvocConf.get(facetCategory.datasetFieldTypeId).containsKey('headers') ? cvocConf.get(facetCategory.datasetFieldTypeId).get('headers').toString() : '{}'}"/>
                                    <f:passThroughAttribute name="data-cvoc-protocol" value="#{cvocConf.get(facetCategory.datasetFieldTypeId).getString('protocol','')}" />
                                </c:if>
                            </h:outputText>
                            <h:outputFormat value=" &#40;{0}&#41;">
                                <f:param value="#{facetLabel.count}"/>
                            </h:outputFormat>
                            <span class="glyphicon glyphicon-remove"></span>
                            <f:param name="q" value="#{DataversePage.query}"/>
                            <c:forEach items="#{DataversePage.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                <f:param name="fq#{status.index}" value='#{clickedFilterQuery}' disable="#{clickedFilterQuery == facetLabel.filterQuery}"/>
                            </c:forEach>
                            <f:param name="types" value="#{DataversePage.selectedTypesString}"/>
                            <f:param name="sort" value="#{DataversePage.sortField}"/>
                            <f:param name="order" value="#{DataversePage.sortOrder}"/>
                        </h:outputLink>
                    </p:dataList>
                    <ui:fragment rendered="#{facetCategory.name != DataversePage.searchFieldType and facetCategory.name != DataversePage.searchFieldSubtree}">
                        <p:panelGrid styleClass="facetsMoreLess" columns="2" rendered="#{(DataversePage.getNumberOfFacets(facetCategory.name,5) lt facetCategory.facetLabel.size()) or (DataversePage.getNumberOfFacets(facetCategory.name,5) gt 5)}">
                            <ui:fragment>
                                <p:commandLink actionListener="#{DataversePage.incrementFacets(facetCategory.name,-5)}" update="facetCategoryList" rendered="#{DataversePage.getNumberOfFacets(facetCategory.name,5) gt 5}">#{bundle.less}</p:commandLink>
                            </ui:fragment>
                            <ui:fragment>
                                <p:commandLink actionListener="#{DataversePage.incrementFacets(facetCategory.name,5)}" update="facetCategoryList" rendered="#{DataversePage.getNumberOfFacets(facetCategory.name,5) lt facetCategory.facetLabel.size()}">#{bundle.more}</p:commandLink>
                            </ui:fragment>
                        </p:panelGrid>
                    </ui:fragment>
                </p:dataList>
            </h:form>
            <!-- "facets temporarily unavailable" message: -->
            <h:form id="facetsUnavailable" rendered="#{SearchIncludeFragment.facetsDisabled}">
                <div class="clearfix">
                    <h:outputText value="#{bundle['dataverse.results.solrFacetsDisabled']}" styleClass="facetTypeLink"/>
                </div>
            </h:form>
        </div>
        <div id="dv-main" class="col-sm-8 col-md-9">
            <!--DEBUG BEGIN-->
            <div jsf:rendered="#{dataverseSession.debug}" style="background-color: lightgray">
                <tt>
                    <h:outputText value="mode:#{SearchIncludeFragment.mode} "/>
                    <h:outputText value="sort=#{SearchIncludeFragment.sortField}:#{SearchIncludeFragment.sortOrder}"/><br/>
                    <h:outputText value="#{SearchIncludeFragment.filterQueriesDebug}"/><br/>
                    <h:outputText value="solrIsDown=#{SearchIncludeFragment.solrIsDown}"/><br/>
                    <h:outputText value="errorFromSolr: #{SearchIncludeFragment.errorFromSolr}" rendered="#{SearchIncludeFragment.errorFromSolr != null}"/>
                </tt>
            </div>
            <!--DEBUG END-->

            <!--toggle sidebar button-->
            <p class="visible-xs-block">
              <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas"><span class="glyphicon glyphicon-chevron-left"></span> #{bundle['dataverse.results.btn.filterResults']}</button>
            </p>

            <!-- Message for zero results -->
            <div id="emptyResults" class="emptyResults bg-warning" jsf:rendered="#{(SearchIncludeFragment.searchResultsList.size() == 0) and (!SearchIncludeFragment.wasSolrErrorEncountered())}">
                <ui:fragment rendered="#{SearchIncludeFragment.mode == SearchIncludeFragment.searchModeString}">
                    <!--THIS IS EMPTY / SEARCH-->
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses eq 0 and SearchIncludeFragment.facetCountDatasets eq 0 and SearchIncludeFragment.facetCountFiles eq 0}">
                        <!--SEARCH ZERO COUNTS-->
                        <p><h:outputFormat value="#{bundle['dataverse.results.empty.zero']}" escape="false">
                                <f:param value="#{settingsWrapper.guidesBaseUrl}"/>
                                <f:param value="#{settingsWrapper.guidesVersion}"/>
                            </h:outputFormat></p>
                    </ui:fragment>
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses gt 0 or SearchIncludeFragment.facetCountDatasets gt 0 or SearchIncludeFragment.facetCountFiles gt 0}">
                        <!--SEARCH HIDDEN-->
                        <p><h:outputFormat value="#{bundle['dataverse.results.empty.hidden']}" escape="false">
                                <f:param value="#{settingsWrapper.guidesBaseUrl}"/>
                                <f:param value="#{settingsWrapper.guidesVersion}"/>
                            </h:outputFormat></p>
                    </ui:fragment>
                    <ui:fragment rendered="#{SearchIncludeFragment.errorFromSolr != null}">
                        <p>
                            <a rel="nofollow" data-toggle="collapse" data-parent="#emptyResults" href="#technicalDetails" aria-expanded="true" aria-controls="technicalDetails">[+] #{bundle['dataverse.results.empty.link.technicalDetails']}</a>
                        </p>
                        <div id="technicalDetails" class="collapse">
                            <pre><h:outputText value="#{SearchIncludeFragment.errorFromSolr}"/></pre>
                        </div>
                    </ui:fragment>
                </ui:fragment>
                <ui:fragment rendered="#{!dataverseSession.user.authenticated and SearchIncludeFragment.mode == SearchIncludeFragment.browseModeString}">
                    <!--THIS IS EMPTY / BROWSE / GUEST-->
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses eq 0 and SearchIncludeFragment.facetCountDatasets eq 0 and SearchIncludeFragment.facetCountFiles eq 0}">
                        <!--BROWSE GUEST ZERO COUNTS-->
                        <p>
                            <h:outputFormat value="#{bundle['dataverse.results.empty.browse.guest.zero']}" escape="false">
                                <f:param value="#{navigationWrapper.redirectPage}"/>
                            </h:outputFormat>
                        </p>
                    </ui:fragment>
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses gt 0 or SearchIncludeFragment.facetCountDatasets gt 0 or SearchIncludeFragment.facetCountFiles gt 0}">
                        <!--BROWSE GUEST HIDDEN-->
                        <p>
                            <h:outputFormat value="#{bundle['dataverse.results.empty.browse.guest.hidden']}" escape="false">
                                <f:param value="#{navigationWrapper.redirectPage}"/>
                            </h:outputFormat>
                        </p>
                    </ui:fragment>
                </ui:fragment>
                <ui:fragment rendered="#{dataverseSession.user.authenticated and !(permissionsWrapper.canIssueCreateDataverseCommand(SearchIncludeFragment.dataverse) or permissionsWrapper.canIssueCreateDatasetCommand(SearchIncludeFragment.dataverse)) and SearchIncludeFragment.mode == SearchIncludeFragment.browseModeString}">
                    <!--THIS IS EMPTY / BROWSE / LOGGED IN / NO PERMS-->
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses eq 0 and SearchIncludeFragment.facetCountDatasets eq 0 and SearchIncludeFragment.facetCountFiles eq 0}">
                        <!--BROWSE NO_ADD_BUTTON ZERO COUNTS-->
                        <p>#{bundle['dataverse.results.empty.browse.loggedin.noperms.zero']}</p>
                    </ui:fragment>
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses gt 0 or SearchIncludeFragment.facetCountDatasets gt 0 or SearchIncludeFragment.facetCountFiles gt 0}">
                        <!--BROWSE NO_ADD_BUTTON HIDDEN-->
                        <p>#{bundle['dataverse.results.empty.browse.loggedin.noperms.hidden']}</p>
                    </ui:fragment>
                </ui:fragment>
                <ui:fragment rendered="#{dataverseSession.user.authenticated and (permissionsWrapper.canIssueCreateDataverseCommand(SearchIncludeFragment.dataverse) or permissionsWrapper.canIssueCreateDatasetCommand(SearchIncludeFragment.dataverse)) and SearchIncludeFragment.mode == SearchIncludeFragment.browseModeString}">
                    <!--THIS IS EMPTY / BROWSE / LOGGED IN / PERMS-->
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses eq 0 and SearchIncludeFragment.facetCountDatasets eq 0 and SearchIncludeFragment.facetCountFiles eq 0}">
                        <!--BROWSE CAN_ADD ZERO COUNTS-->
                        <p>
                            <h:outputFormat value="#{dataverseRedirectPage == 'dataverseuser.xhtml' ? bundle['account.results.empty.browse.loggedin.perms.zero'] : bundle['dataverse.results.empty.browse.loggedin.perms.zero']}" escape="false">
                                <f:param value="#{settingsWrapper.guidesBaseUrl}"/>
                                <f:param value="#{settingsWrapper.guidesVersion}"/>
                            </h:outputFormat>
                        </p>
                    </ui:fragment>
                    <ui:fragment rendered="#{SearchIncludeFragment.facetCountDataverses gt 0 or SearchIncludeFragment.facetCountDatasets gt 0 or SearchIncludeFragment.facetCountFiles gt 0}">
                        <!--BROWSE CAN_ADD HIDDEN-->
                        <p>#{bundle['dataverse.results.empty.browse.loggedin.perms.hidden']}</p>
                    </ui:fragment>
                </ui:fragment>
            </div>

            <div id="resultsFacetsTopBlock" jsf:rendered="#{!empty SearchIncludeFragment.filterQueries}">
                <ui:fragment rendered="#{(SearchIncludeFragment.wasSolrErrorEncountered())}">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="bg-danger padding-12 margin-top margin-bottom">
                                <p><h:outputFormat value=" #{bundle['dataverse.search.facet.error']}" escape="false">
                                    <f:param value="#{SearchIncludeFragment.dataverse.alias}"/>                                    
                                </h:outputFormat></p>
                            </div>
                        </div>
                    </div>   
                </ui:fragment>

                <ui:repeat value="#{SearchIncludeFragment.filterQueries}" var="filterQuery" rendered="#{!SearchIncludeFragment.wasSolrErrorEncountered()}">
                    <ui:param name="friendlyNames" value="#{SearchIncludeFragment.getFriendlyNamesFromFilterQuery(filterQuery)}"/>
                    <ui:param name="filterType" value="#{SearchIncludeFragment.getTypeFromFilterQuery(filterQuery)}"/>
                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}" styleClass="facetLink facetSelected" rendered="#{not empty friendlyNames
                                and filterType != DataversePage.searchFieldType and filterType != DataversePage.searchFieldSubtree}">
                        <h:outputText value="#{friendlyNames.get(0)}: "/>
                        <h:outputText value="#{friendlyNames.get(1)}">
                                <f:passThroughAttribute name="lang" value="#{DatasetPage.getFieldLanguage(cvocConf.get(SearchIncludeFragment.getFieldTypeId(friendlyNames.get(0))).getString('languages'))}" />
                                <f:passThroughAttribute name="data-cvoc-service-url" value="#{cvocConf.get(SearchIncludeFragment.getFieldTypeId(friendlyNames.get(0))).getString('cvoc-url','')}" />
                                <f:passThroughAttribute name="data-cvoc-headers" value="#{cvocConf.get(SearchIncludeFragment.getFieldTypeId(friendlyNames.get(0))).containsKey('headers') ? cvocConf.get(SearchIncludeFragment.getFieldTypeId(friendlyNames.get(0))).get('headers').toString() : '{}'}"/>
                                <f:passThroughAttribute name="data-cvoc-protocol" value="#{cvocConf.get(SearchIncludeFragment.getFieldTypeId(friendlyNames.get(0))).getString('protocol','')}" />
                        </h:outputText>
                        <span class="glyphicon glyphicon-remove"></span>
                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}' disable="#{clickedFilterQuery == filterQuery}"/>
                        </c:forEach>
                        <f:param name="types" value="#{SearchIncludeFragment.selectedTypesString}"/>
                        <f:param name="sort" value="#{SearchIncludeFragment.sortField}"/>
                        <f:param name="order" value="#{SearchIncludeFragment.sortOrder}"/>
                    </h:outputLink>
                </ui:repeat>
            </div>

            <div id="resultsCountPaginatorBlock" class="row" jsf:rendered="#{SearchIncludeFragment.searchResultsCount > 0}">
                <!-- RESULTS COUNT -->
                <div class="results-count col-xs-6">
                    <h:outputFormat value="#{bundle['dataverse.results.count.toofresults']}">
                        <f:param value="#{SearchIncludeFragment.paginationGuiStart}"/>
                        <f:param value="#{SearchIncludeFragment.paginationGuiEnd}"/>
                        <f:param value="#{SearchIncludeFragment.searchResultsCount}"/>
                    </h:outputFormat>
                </div>
                <!-- SORT + PAGINATOR -->
                <div class="results-sort-pagination col-xs-6">
                    <!-- SORT BY -->
                    <div class="btn-group pull-right">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <span class="glyphicon glyphicon-sort"/> #{bundle['dataverse.results.btn.sort']} <span class="caret"/>
                        </button>
                        <ul class="dropdown-menu pull-right text-left">
                            <li>
                                <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}">
                                    <h:outputText value="#{bundle['dataverse.results.btn.sort.option.nameAZ']}" styleClass="#{SearchIncludeFragment.sortedByNameAsc ? 'highlightBold' : ''}"/>
                                    <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                                    <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                        <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                                    </c:forEach>
                                    <f:param name="types" value="#{SearchIncludeFragment.selectedTypesString}"/>
                                    <f:param name="page" value="1"/>
                                    <f:param name="sort" value="#{SearchIncludeFragment.searchFieldNameSort}"/>
                                    <f:param name="order" value="#{SearchIncludeFragment.ASCENDING}"/>
                                </h:outputLink>
                            </li>
                            <li>
                                <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}">
                                    <h:outputText value="#{bundle['dataverse.results.btn.sort.option.nameZA']}" styleClass="#{SearchIncludeFragment.sortedByNameDesc ? 'highlightBold' : ''}"/>
                                    <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                                    <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                        <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                                    </c:forEach>
                                    <f:param name="types" value="#{SearchIncludeFragment.selectedTypesString}"/>
                                    <f:param name="page" value="1"/>
                                    <f:param name="sort" value="#{SearchIncludeFragment.searchFieldNameSort}"/>
                                    <f:param name="order" value="#{SearchIncludeFragment.DESCENDING}"/>
                                </h:outputLink>
                            </li>
                            <li>
                                <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}">
                                    <h:outputText value="#{bundle['dataverse.results.btn.sort.option.newest']}" styleClass="#{SearchIncludeFragment.sortedByReleaseDateDesc? 'highlightBold' : ''}"/>
                                    <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                                    <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                        <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                                    </c:forEach>
                                    <f:param name="types" value="#{SearchIncludeFragment.selectedTypesString}"/>
                                    <f:param name="page" value="1"/>
                                    <f:param name="sort" value="#{SearchIncludeFragment.searchFieldReleaseOrCreateDate}"/>
                                    <f:param name="order" value="#{SearchIncludeFragment.DESCENDING}"/>
                                </h:outputLink>
                            </li>
                            <li>
                                <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}">
                                    <h:outputText value="#{bundle['dataverse.results.btn.sort.option.oldest']}" styleClass="#{SearchIncludeFragment.sortedByReleaseDateAsc? 'highlightBold' : ''}"/>
                                    <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                                    <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                        <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                                    </c:forEach>
                                    <f:param name="types" value="#{SearchIncludeFragment.selectedTypesString}"/>
                                    <f:param name="page" value="1"/>
                                    <f:param name="sort" value="#{SearchIncludeFragment.searchFieldReleaseOrCreateDate}"/>
                                    <f:param name="order" value="#{SearchIncludeFragment.ASCENDING}"/>
                                </h:outputLink>
                            </li>
                            <ui:fragment rendered="#{SearchIncludeFragment.mode == SearchIncludeFragment.searchModeString}">
                                <li>
                                    <h:outputLink rel="nofollow" value="#{widgetWrapper.wrapURL(page)}">
                                        <h:outputText value="#{bundle['dataverse.results.btn.sort.option.relevance']}" styleClass="#{SearchIncludeFragment.sortedByRelevance ? 'highlightBold' : ''}"/>
                                        <f:param name="q" value="#{SearchIncludeFragment.query}"/>
                                        <c:forEach items="#{SearchIncludeFragment.filterQueries}" var="clickedFilterQuery" varStatus="status">
                                            <f:param name="fq#{status.index}" value='#{clickedFilterQuery}'/>
                                        </c:forEach>
                                        <f:param name="types" value="#{SearchIncludeFragment.selectedTypesString}"/>
                                        <f:param name="page" value="1"/>
                                        <f:param name="sort" value="#{SearchIncludeFragment.searchFieldRelevance}"/>
                                        <f:param name="order" value="#{SearchIncludeFragment.DESCENDING}"/>
                                    </h:outputLink>
                                </li>
                            </ui:fragment>
                        </ul>
                    </div>
                </div>
            </div>

            <o:importFunctions type="org.omnifaces.el.functions.Strings" />
            <ui:param name="descriptionAbbreviationThreshold" value="350"/>
            <!--CARDS-->
            <h:dataTable id="resultsTable" styleClass="#{SearchIncludeFragment.searchResultsCount > 0 ? '' : 'resultsNone'}" value="#{SearchIncludeFragment.searchResultsList}" var="result"
                         rendered="#{SearchIncludeFragment.searchResultsList.size() > 0}">
                <h:column>
                    <ui:fragment rendered="#{dataverseSession.debug}">
                        <h:outputText value="score: #{result.score}" rendered="#{SearchIncludeFragment.mode == SearchIncludeFragment.searchModeString}"/>
                    </ui:fragment>
                    <!--DATAVERSE CARDS-->
                    <div class="dataverseResult clearfix" jsf:rendered="#{result.type == 'dataverses'}">
                        <div class="card-title-icon-block">
                            <span class="glyphicon glyphicon-link text-brand pull-right" title="#{bundle.linked}" jsf:rendered="#{!SearchIncludeFragment.rootDv and !result.isInTree}"/>
                            <span class="glyphicon glyphicon-new-window text-brand pull-right" title="#{bundle.harvested}" jsf:rendered="#{result.harvested}"/>
                            <span class="icon-dataverse text-brand pull-right" title="#{bundle.dataverse}"/>
                            <c:set var="dvUrl" value="/dataverse/#{result.dataverseAlias}"/>
                            <h:outputLink value="#{!SearchIncludeFragment.rootDv and !result.isInTree ? dvUrl : widgetWrapper.wrapURL(dvUrl)}" target="#{!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView ? '_blank' : ''}">
                                <h:outputText value="#{result.name}" style="padding:4px 0;" rendered="#{result.nameHighlightSnippet == null}"/>
                                <h:outputText value="#{result.nameHighlightSnippet}" style="padding:4px 0;" rendered="#{result.nameHighlightSnippet != null}" escape="false"/>
                                <h:outputText value=" (#{result.entityId})" style="padding:4px 0;" rendered="#{dataverseSession.debug}"/>
                            </h:outputLink>
                            <h:outputText value="(#{result.dataverseAffiliation})" styleClass="text-muted" style="margin-left: .5em;" rendered="#{!empty result.dataverseAffiliation and result.dataverseAffiliationHighlightSnippet == null}"/>
                            <h:outputText value="(#{result.dataverseAffiliationHighlightSnippet})" styleClass="text-muted" style="margin-left: .5em;" rendered="#{result.dataverseAffiliationHighlightSnippet != null}" escape="false"/>
                            <h:outputText value="#{bundle['dataset.versionUI.draft']}" styleClass="label label-primary" rendered="#{result.draftState}"/>
                            <h:outputText value="#{result.userRole}" styleClass="label label-primary" rendered="#{!empty result.userRole}"/>
                            <h:outputText value="#{bundle['dataset.versionUI.unpublished']}" styleClass="label label-warning" rendered="#{result.unpublishedState}"/>
                        </div>
                        <div class="card-preview-icon-block text-center">
                            <h:outputLink rel="nofollow" value="#{!SearchIncludeFragment.rootDv and !result.isInTree ? dvUrl : widgetWrapper.wrapURL(dvUrl)}" target="#{!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView ? '_blank' : ''}">
                                <img src="#{result.imageUrl}" jsf:rendered="#{!empty result.imageUrl}" alt="#{of:format1(bundle['alt.logo'], result.name)}"/>
                                <span class="icon-dataverse text-brand" jsf:rendered="#{empty result.imageUrl}"/>
                                <f:passThroughAttribute name="aria-label" value="#{of:format1(bundle['alt.logo'], result.name)}"/>
                            </h:outputLink>
                        </div>

                        <h:outputText value="#{result.dateToDisplayOnCard}" styleClass="text-muted" style="margin-right:.5em;"/>

                        <c:set var="dvParentUrl" value="/dataverse/#{result.dataverseParentAlias}"/>
                        <h:outputLink rel="nofollow" value="#{!SearchIncludeFragment.rootDv and !result.isInTree ? dvParentUrl : widgetWrapper.wrapURL(dvParentUrl)}" target="#{!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView ? '_blank' : ''}" rendered="#{result.parent.id != SearchIncludeFragment.dataverse.id}">
                            <h:outputText value="#{result.parent.get('name')}"/>
                        </h:outputLink>

                        <hr style="margin:.5em;border:0;"/>

                        <h:outputText value="#{Strings:abbreviate(result.descriptionNoSnippet, descriptionAbbreviationThreshold)}" rendered="#{result.descriptionSnippets.size() eq 0}"/>

                        <ui:repeat value="#{result.descriptionSnippets}" var="snippet" varStatus="varStatus"
                                   rendered="#{result.descriptionSnippets.size() gt 0}">
                            <h:outputText value="#{snippet}" escape="false"/>
                            <h:outputText value="... " rendered="#{varStatus.last != true}"/>
                        </ui:repeat>

                        <ui:fragment rendered="#{false and result.matchedFields.size() > 0}">
                            <h:outputText value="#{bundle['dataverse.results.cards.foundInMetadata']} "/>
                            <ui:repeat value="#{result.matchedFields}" var="field" varStatus="varStatus">
                                <h:outputText value="#{field}"/>
                                <h:outputText value=", " rendered="#{varStatus.last != true}"/>
                            </ui:repeat>
                        </ui:fragment>

                        <ui:repeat value="#{result.highlightsAsList}" var="highlight" rendered="#{result.highlightsAsList.size() gt 0}">
                            <ui:repeat value="#{highlight.snippets}" var="snippet">
                                <div>
                                    <h:outputText value="#{highlight.solrField.nameSearchable}: #{snippet}" escape="false"/>
                                    <ui:param value="#{highlight.solrField.nameFacetable}:intentional" name="unfriendly"/>
                                </div>
                            </ui:repeat>
                        </ui:repeat>
                    </div>
                    <!--DATASET CARDS-->
                    <div class="datasetResult clearfix" jsf:rendered="#{result.type == 'datasets'}">
                        <div class="card-title-icon-block">
                            <o:importFunctions type="edu.harvard.iq.dataverse.dataset.DatasetUtil" />
                            <span class="glyphicon glyphicon-link text-info pull-right" title="#{bundle.linked}" jsf:rendered="#{!SearchIncludeFragment.rootDv and !result.isInTree}"/>
                            <span class="glyphicon glyphicon-new-window text-info pull-right" title="#{bundle.harvested}" jsf:rendered="#{result.harvested}"/>
                            <span class="icon-dataset text-info pull-right" title="#{bundle.dataset}"/>
                            <a href="#{!SearchIncludeFragment.rootDv and !result.isInTree ? result.datasetUrl : widgetWrapper.wrapURL(result.datasetUrl)}" target="#{(!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView) or result.harvested ? '_blank' : ''}">
                                <h:outputText value="#{result.nameSort}" style="padding:4px 0;" rendered="#{result.titleHighlightSnippet == null}"/>
                                <h:outputText value="#{result.titleHighlightSnippet}" style="padding:4px 0;" rendered="#{result.titleHighlightSnippet != null}" escape="false"/>
                                <h:outputText value=" (#{result.entityId})" style="padding:4px 0;" rendered="#{dataverseSession.debug}"/></a>

                            <h:outputText value="#{bundle['dataset.versionUI.draft']}" styleClass="label label-primary" rendered="#{result.draftState}"/>
                            <h:outputText value="#{bundle['dataset.versionUI.inReview']}" styleClass="label label-success" rendered="#{result.inReviewState}"/>
                            <h:outputText value="#{bundle['dataset.versionUI.unpublished']}" styleClass="label label-warning" rendered="#{result.unpublishedState}"/>
                            <h:outputText value="#{bundle['dataset.versionUI.deaccessioned']}" styleClass="label label-danger" rendered="#{result.deaccessionedState}"/>
                            <h:outputText value="#{bundle['embargoed']}" styleClass="label label-primary" rendered="#{SearchIncludeFragment.isActivelyEmbargoed(result)}"/>
                            <h:outputText value="#{bundle['retentionExpired']}" styleClass="label label-warning" rendered="#{SearchIncludeFragment.isRetentionExpired(result)}"/>
                            <h:outputText value="#{DatasetUtil:getLocaleCurationStatusLabelFromString(result.curationStatus)}" styleClass="label label-info curation-status" rendered="#{SearchIncludeFragment.canSeeCurationStatus(result.entityId)}"/>
                            <h:outputText value="#{result.userRole}" styleClass="label label-primary" rendered="#{!empty result.userRole}"/>
                            <h:outputText value="#{bundle['incomplete']}" styleClass="label label-danger" rendered="#{!result.harvested and !SearchIncludeFragment.isValid(result)}"/>
                        </div>
                        <div class="card-preview-icon-block text-center">
                            <a rel="nofollow" href="#{!SearchIncludeFragment.rootDv and !result.isInTree ? result.datasetUrl : widgetWrapper.wrapURL(result.datasetUrl)}" target="#{(!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView) or result.harvested ? '_blank' : ''}" aria-label="#{result.title}">
                                <img src="#{result.imageUrl}" jsf:rendered="#{!empty result.imageUrl and !result.deaccessionedState}" alt="#{result.title}"/>
                                <span class="icon-dataset" jsf:rendered="#{empty result.imageUrl or result.deaccessionedState}"/>
                            </a>
                        </div>

                        <h:outputText styleClass="text-muted" value="#{result.dateToDisplayOnCard}"/>

                        <h:outputText styleClass="text-muted" value=" - " rendered="#{result.parent.id != SearchIncludeFragment.dataverse.id}"/>
                        
                        <c:set var="dvParentAlias" value="/dataverse/#{result.dataverseAlias}"/>
                        <h:outputLink rel="nofollow" value="#{!SearchIncludeFragment.rootDv and !result.isInTree ? dvParentAlias : widgetWrapper.wrapURL(dvParentAlias)}" target="#{(!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView) or result.harvested ? '_blank' : ''}" rendered="#{result.parent.id != SearchIncludeFragment.dataverse.id}">
                            <h:outputText value="#{result.parent.get('name')}"/>
                        </h:outputLink>

                        <div class="resultDatasetCitationBlock #{result.deaccessionedState ? 'alert alert-danger bg-danger' : 'alert alert-info bg-citation'}">
                            <h:outputText value="#{result.citationHtml != null ? result.citationHtml : result.citation}" escape="false"/>
                        </div>
                        
                        <h:outputText value="#{Strings:abbreviate(result.descriptionNoSnippet, descriptionAbbreviationThreshold)}" rendered="#{result.descriptionSnippets.size() eq 0}"/>

                        <ui:repeat value="#{result.descriptionSnippets}" var="snippet" varStatus="varStatus"
                                   rendered="#{result.descriptionSnippets.size() gt 0}">
                            <h:outputText value="... #{snippet} ..." escape="false"/>
                        </ui:repeat>

                        <ui:fragment rendered="#{false and result.matchedFields.size() > 0}">
                            <h:outputText value="#{bundle['dataverse.results.cards.foundInMetadata']} "/>
                            <ui:repeat value="#{result.matchedFields}" var="field" varStatus="varStatus">
                                <h:outputText value="#{field}"/>
                                <h:outputText value=", " rendered="#{varStatus.last != true}"/>
                            </ui:repeat>
                        </ui:fragment>

                        <ui:repeat value="#{result.highlightsAsList}" var="highlight" rendered="#{result.highlightsAsList.size() > 0}">
                            <ui:repeat value="#{highlight.snippets}" var="snippet">
                                <div>
                                    <h:outputText value='#{highlight.displayName}: '/>
                                    <o:importFunctions type="edu.harvard.iq.dataverse.util.MarkupChecker" />
                                    <h:outputText value="#{covcConf.isEmpty() ? snippet: MarkupChecker:stripAllTags(snippet)}" escape="false">
                                        <c:if test="#{!cvocConf.isEmpty()}">
                                            <f:passThroughAttribute name="lang" value="#{DatasetPage.getFieldLanguage(cvocConf.get(datasetFieldServiceBean.findByName(highlight.solrField.nameSearchable).id).getString('languages'))}" />
                                            <f:passThroughAttribute name="data-cvoc-service-url" value="#{cvocConf.get(datasetFieldServiceBean.findByName(highlight.solrField.nameSearchable).id).getString('cvoc-url','')}" />
                                            <f:passThroughAttribute name="data-cvoc-headers" value="#{cvocConf.get(datasetFieldServiceBean.findByName(highlight.solrField.nameSearchable).id).containsKey('headers') ? cvocConf.get(datasetFieldServiceBean.findByName(highlight.solrField.nameSearchable).id).get('headers').toString() : '{}'}"/>
                                            <f:passThroughAttribute name="data-cvoc-protocol" value="#{cvocConf.get(datasetFieldServiceBean.findByName(highlight.solrField.nameSearchable).id).getString('protocol','')}" />
                                        </c:if>
                                    </h:outputText>
                                </div>
                            </ui:repeat>
                        </ui:repeat>

                        <div jsf:rendered="#{result.harvested and !empty result.harvestingDescription}" class="text-muted small margin-top-half">
                            <h:outputText value="#{result.harvestingDescription}"/>
                        </div>
                    </div>
                    <!--FILE CARDS-->
                    <div class="fileResult clearfix" jsf:rendered="#{result.type == 'files'}">
                        <div class="card-title-icon-block">
                            <span class="glyphicon glyphicon-link text-muted pull-right" title="#{bundle.linked}" jsf:rendered="#{!SearchIncludeFragment.rootDv and !result.isInTree}"/>
                            <span class="glyphicon glyphicon-new-window text-muted pull-right" title="#{bundle.harvested}" jsf:rendered="#{result.harvested}"/>
                            <span class="icon-file text-muted pull-right" title="#{bundle.file}"/>

                            <span class="text-danger glyphicon glyphicon-lock" data-toggle="tooltip" title="#{bundle.restricted}" jsf:rendered="#{result.entity.restricted and !permissionsWrapper.hasDownloadFilePermission(result.entity)}"/>
                            <span class="text-success icon-unlock" data-toggle="tooltip" title="#{bundle.restrictedaccess}" jsf:rendered="#{result.entity.restricted and permissionsWrapper.hasDownloadFilePermission(result.entity)}"/>
                            <a rel="nofollow" href="#{!SearchIncludeFragment.rootDv and !result.isInTree ? (result.harvested ? result.fileDatasetUrl : result.fileUrl) : widgetWrapper.wrapURL(result.harvested ? result.fileDatasetUrl : result.fileUrl)}" target="#{(!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView) or result.harvested ? '_blank' : ''}">
                                <h:outputText value="#{result.name}" style="padding:4px 0;" rendered="#{result.nameHighlightSnippet == null}"/>
                                <h:outputText value="#{result.nameHighlightSnippet}" style="padding:4px 0;" rendered="#{result.nameHighlightSnippet != null}" escape="false"/>
                                <h:outputText value=" (#{result.entityId})" style="padding:4px 0;" rendered="#{dataverseSession.debug}"/></a>
                            <h:outputText value="#{bundle['dataset.versionUI.draft']}" styleClass="label label-primary" rendered="#{result.draftState}"/>
                            <h:outputText value="#{bundle['dataset.versionUI.inReview']}" styleClass="label label-success" rendered="#{result.inReviewState}"/>
                            <h:outputText value="#{bundle['dataset.versionUI.unpublished']}" styleClass="label label-warning" rendered="#{result.unpublishedState}"/>
                            <h:outputText value="#{bundle['embargoed']}" styleClass="label label-primary" rendered="#{SearchIncludeFragment.isActivelyEmbargoed(result)}"/>
                            <h:outputText value="#{bundle['retentionExpired']}" styleClass="label label-danger" rendered="#{SearchIncludeFragment.isRetentionExpired(result)}"/>
                            <h:outputText value="#{result.userRole}" styleClass="label label-primary" rendered="#{!empty result.userRole}"/>
                        </div>

                        <div class="card-preview-icon-block text-center">
                            <a rel="nofollow" href="#{!SearchIncludeFragment.rootDv and !result.isInTree ? (result.harvested ? result.fileDatasetUrl : result.fileUrl) : widgetWrapper.wrapURL(result.harvested ? result.fileDatasetUrl : result.fileUrl)}" target="#{(!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView) or result.harvested ? '_blank' : ''}" aria-label="#{result.name}">
                                <img src="#{result.imageUrl}" jsf:rendered="#{!empty result.imageUrl}" alt="#{result.name}"/>
                                <span class="icon-#{dataFileServiceBean.getFileThumbnailClass(result.entity)} text-muted h1"
                                      jsf:rendered="#{empty result.imageUrl}"/>
                            </a>
                        </div>

                        <div class="text-muted">
                            <h:outputText value="#{result.dateToDisplayOnCard} - "/>
                            <a rel="nofollow" href="#{!SearchIncludeFragment.rootDv and !result.isInTree ? result.fileDatasetUrl : widgetWrapper.wrapURL(result.fileDatasetUrl)}" target="#{(!SearchIncludeFragment.rootDv and !result.isInTree and widgetWrapper.widgetView) or result.harvested ? '_blank' : ''}">
                                <h:outputText value="#{result.parent.get('name')}"/></a>
                        </div>

                        <div class="text-muted">
                            <h:outputText value="#{bundle['dataverse.results.cards.files.tabularData']}" rendered="#{!empty SearchIncludeFragment.tabularDataDisplayInfo(result.entity)}"/>
                            <h:outputText value="#{result.filetype}" rendered="#{empty SearchIncludeFragment.tabularDataDisplayInfo(result.entity) and result.fileTypeHighlightSnippet == null}"/>
                            <h:outputText value="#{result.fileTypeHighlightSnippet}" rendered="#{empty SearchIncludeFragment.tabularDataDisplayInfo(result.entity) and result.fileTypeHighlightSnippet != null}" escape="false"/>
                            <h:outputText value=" - #{SearchIncludeFragment.dataFileSizeDisplay(result.entity)}" rendered="#{!result.harvested}"/>
                            <h:outputText value=" - " rendered="#{!result.harvested and !SearchIncludeFragment.isTabular(result.entity) and !(empty result.fileChecksumValue)}"/>
                            <span class="checksum-block" jsf:rendered="#{!result.harvested and !SearchIncludeFragment.isTabular(result.entity) and !(empty result.fileChecksumValue)}">
                                <span class="checksum-truncate checksum-tooltip" style="margin-right:3px;"
                                          data-toggle="tooltip" data-placement="top" data-html="true"
                                          data-clipboard-action="copy"
                                          data-clipboard-text="#{result.fileChecksumValue}"
                                          title="#{bundle['file.metaData.checksum.copy']}&lt;br/&gt;#{result.fileChecksumValue}">#{result.fileChecksumType}: #{result.fileChecksumValue}</span>
                                <span class="glyphicon glyphicon-copy btn-copy checksum-tooltip"
                                        data-toggle="tooltip" data-placement="top" data-html="true"
                                        data-clipboard-action="copy"
                                        data-clipboard-text="#{result.fileChecksumValue}" title="#{bundle['file.metaData.checksum.copy']}&lt;br/&gt;#{result.fileChecksumValue}"></span>
                            </span>
                            <!-- if tabular data file, display number of variables and observations, and unf -->
                            <span class="unf-block" jsf:rendered="#{!empty SearchIncludeFragment.tabularDataDisplayInfo(result.entity)}">
                                <h:outputText value=" - #{SearchIncludeFragment.tabularDataDisplayInfo(result.entity)}"/>
                                <h:outputText value=" - " rendered="#{!empty SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}"/>
                                <span class="checksum-truncate checksum-tooltip" style="margin-right:3px;" jsf:rendered="#{!empty SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}"
                                          data-toggle="tooltip" data-placement="top" data-html="true"
                                          data-clipboard-action="copy"
                                          data-clipboard-text="#{SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}"
                                          title="#{bundle['file.metaData.checksum.copy']}&lt;br/&gt;#{SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}">#{SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}</span>
                                <span class="glyphicon glyphicon-copy btn-copy checksum-tooltip" jsf:rendered="#{!empty SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}"
                                        data-toggle="tooltip" data-placement="top" data-html="true"
                                        data-clipboard-action="copy"
                                        data-clipboard-text="#{SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}" title="#{bundle['file.metaData.checksum.copy']}&lt;br/&gt;#{SearchIncludeFragment.tabularDataUnfDisplay(result.entity)}"></span>
                            </span>
                        </div>

                        <div class="file-tags-block" jsf:rendered="#{(!empty result.fileCategories) or (!empty result.tabularDataTags)}">
                            <ui:repeat value="#{result.fileCategories}" var="cat">
                                <h:outputText value="#{cat}" styleClass="label label-default"/>
                            </ui:repeat>
                            <ui:repeat value="#{result.tabularDataTags}" var="tag">
                                <h:outputText value="#{tag}" styleClass="label label-info"/>
                            </ui:repeat>
                        </div>

                        <h:outputText value="#{Strings:abbreviate(result.descriptionNoSnippet, descriptionAbbreviationThreshold)}" rendered="#{result.descriptionSnippets.size() eq 0}"/>

                        <ui:repeat value="#{result.descriptionSnippets}" var="snippet" varStatus="varStatus"
                                   rendered="#{result.descriptionSnippets.size() gt 0}">
                            <h:outputText value="#{snippet}" escape="false"/>
                            <h:outputText value="... " rendered="#{varStatus.last != true}"/>
                        </ui:repeat>

                        <div jsf:rendered="#{result.highlightsAsList.size() > 0}">
                            <ui:repeat value="#{result.highlightsAsList}" var="highlight">
                                <ui:repeat value="#{highlight.snippets}" var="snippet">
                                    <div>
                                        <h:outputText value="#{highlight.displayName}: #{snippet}" escape="false"/>
                                    </div>
                                </ui:repeat>
                            </ui:repeat>
                        </div>

                        <div jsf:rendered="#{result.harvested and !empty result.harvestingDescription}">
                            <h:outputText value="#{result.harvestingDescription}" styleClass="text-muted" style="margin-right:.5em;"/>
                        </div>
                    </div>
                </h:column>
            </h:dataTable>
            <!-- BOTTOM PAGINATOR -->
            <ui:include src="search-include-pager.xhtml"></ui:include>
        </div>
    </div>

    <!-- this remote command is called once the page finishes its initial load,
            in order to display the images for the card -->
    <h:form>
        <p:remoteCommand name="postLoad"
                         process="@this"
                         update=":#{p:resolveClientId('resultsTable', view)}"
                         actionListener="#{SearchIncludeFragment.setDisplayCardValues()}" />
    </h:form>

    <ui:include src="addDataFormFragment.xhtml"></ui:include>

</ui:composition>
